package com.example.controller;

import java.io.IOException;
import java.rmi.RemoteException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

import com.example.service.impl.AutoJobcArdARServerImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.example.service.impl.AutoCbsServerImpl;
import com.example.service.impl.AutoJobcArdPIServerImpl;

import net.sf.json.JSONObject;

@RestController
@Component
@RequestMapping("AutoJobcardAR")
public class AutoJobcardARController {

	@Autowired
	public AutoJobcArdARServerImpl AutoJobcArdServer;
	@Autowired
	public AutoCbsServerImpl AutoCbsServer;

	/**
	 * 自动生成与下发舾装专业Jobcard
	 *
	 * @return
	 * @throws IOException
	 */
	@RequestMapping("testAR")
	@ResponseBody
	// @Scheduled(cron = "0 0/2 * * * ?")
	public String dataTransAR() throws IOException {
		AutoJobcArdServer.auto_IssuedJobcardAR_Approve2();//自动过审所有图纸
		AutoJobcArdServer.auto_GenerateJobcard_AR();// 自动生成 AR专业JOBCARD
		//AutoJobcArdServer.auto_synchro_UXMMT_AR();// 自动生成 AR专业JOBCARD 物料缺失追踪
		return "Success";

	}


	/**
	 * 自动生成与下发舾装专业Jobcard
	 *
	 * @return
	 * @throws IOException
	 */
	@RequestMapping("testAR2")
	@ResponseBody
	// @Scheduled(cron = "0 0/2 * * * ?")
	public String dataTransAR2() throws IOException {
//		AutoJobcArdServer.auto_IssuedJobcardAR_Approve2();//自动过审所有图纸
		AutoJobcArdServer.auto_GenerateJobcard_AR();// 自动生成 AR专业JOBCARD
		//AutoJobcArdServer.auto_synchro_UXMMT_AR();// 自动生成 AR专业JOBCARD 物料缺失追踪
		return "Success";

	}

	/**
	 * 自动生成预工作包管线专业
	 *
	 * @return
	 * @throws IOException
	 */
	@RequestMapping("testPI2")
	@ResponseBody
	// @Scheduled(cron = "0 0/2 * * * ?")
	public String auto_PreWorkPackageAR() throws IOException {
		AutoJobcArdServer.auto_PreWorkPackageAR();// 自动生成 PI专业预工作包
		return "Success";

	}




	/**
	 * 自动发送预工作包管线专业
	 *
	 * @return
	 * @throws IOException
	 */
	@RequestMapping("testPI3")
	@ResponseBody
	// @Scheduled(cron = "0 0/2 * * * ?")
	public String auto_SendWorkPackage() throws IOException {
		AutoJobcArdServer.auto_SendWorkPackage();// 自动发送预工作包管线专业
		return "Success";

	}

	/**
	 * 查找相关成功的预工作包 将其下发
	 *
	 * @return
	 * @throws RemoteException
	 * @throws IOException
	 */
	@RequestMapping("testPI4")
	@ResponseBody
	// @Scheduled(cron = "0 0/2 * * * ?")
	public void auto_IssuedWorkPackageJobcardAR_Approve() throws RemoteException {
		AutoJobcArdServer.auto_IssuedWorkPackageJobcardAR_Approve();
	}

//	/**
//	 *
//	 * 为iso图施工单进行备料
//	 * @throws IOException
//	 */
//	@RequestMapping("testAR4")
//	@ResponseBody
//	public void auto_IssuedJobcardAR() throws IOException {
//		AutoJobcArdServer.auto_IssuedJobcardAR();
//	}

	/**
	 * 管线专业套料插件访问接口
	 *
	 * @param param
	 * @return
	 * @throws IOException
	 */
	@RequestMapping("testPI5")
	@ResponseBody
	// @Scheduled(cron = "0 0/2 * * * ?")
	@SuppressWarnings("unchecked")
	public String dataTrans2(@RequestBody JSONObject param) throws IOException {

		AutoJobcArdServer.update_WorkPackageAR(param);

		return "调用成功了~~~";

	}


	@RequestMapping("testPI10")
	@ResponseBody
	// @Scheduled(cron = "0 0/2 * * * ?")
	@SuppressWarnings("unchecked")
	public String dataTrans6() throws IOException {

		return "调用成功了~~~";

	}



	/**
	 * 自动备料与下发舾装专业Jobcard
	 *
	 * @return
	 * @throws IOException
	 */
	@RequestMapping("IssuedJobcardAR")
	@ResponseBody
//	@Scheduled(cron = "0 0 8,12,15,18 * * ?") // 每天的 8,12,15,18 点触发一次
	public String auto_IssuedJobcardAR() throws IOException {
		Calendar ca = Calendar.getInstance();// 得到一个Calendar的实例
		ca.setTime(new Date()); // 设置时间为当前时间
		Date lastMonth = ca.getTime(); // 结果
		SimpleDateFormat yyyyMMddDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		String yyyyMMdd = yyyyMMddDate.format(lastMonth);
		System.err.println("时间：" + yyyyMMdd + "执行了AR专业 自动备料");
		AutoJobcArdServer.auto_IssuedJobcardAR();// 自动备料
		return "Success";

	}


}
